import axios from '@/libs/axios1.js'
let jsonHeaders = {'content-type': 'application/json;charset=UTF-8'}

//获取所有镜像
export const getallImage = (obj,search)=>{
  return axios({
    url:`/resource-manager/image/list`,
    data: obj,
    params:search,
    method:'post',
    headers:jsonHeaders
  })
}

//获取所有配额
export const getallFlavor = (search) => {
  return axios({
    url: `/resource-manager/flavor/list`,
    params:search,
    method: 'get',
    headers: jsonHeaders
  })
}

// 获取所有工程
export const getProjects = params => {
  return axios({
    url: `/topo-edit/projects`,
    method: 'get',
    params: params,
    headers: jsonHeaders
  })
}

// 根据选择的镜像和计算方案，自动生成工程模板
export const templateAutomatic = (data) => {
  return axios({
      url: `/resource-manager/template/automatic?visibility=share`,
      method: 'post',
      data: data,
      headers: jsonHeaders
  });
};

// 通过模板ID创建工程，没有模板时创建空白工程，配额默认为小型
export const creatProject = (id, data, mode) => {
  return axios({
      url: `/topo-edit/project/import/async?templateId=${id}&mode=${mode}`,
      method: 'post',
      data:JSON.stringify(data),
      headers: jsonHeaders,
  })
}

export const getProjectVmList = (projectId, params) => {
  return axios({
    url: `/topo-edit/vm/list/${projectId}`,
    method: 'GET',
    params,
    headers: jsonHeaders,
  })
}

export const vmAccess = (vmId, accessType) => {
  return axios({
    url: `/netns/access/${vmId}/${accessType}`,
    method: 'POST',
    data: {},
    headers: jsonHeaders,
  })
}
